// FFA tag detection by regex
var rgxFfaUrl = new RegExp("http:\/\/adsfac\.eu\/[A-Za-z0-9\._\/-]+", "gm");
var rgxDfaUrl = new RegExp("http:\/\/[a-zA-Z0-9].doubleclick\.net.+\"", "gm");

// TODO: other ad servers

var responseString = "";
var matchString = "";
var FfaTagList = new Array();
var DfaTagList = new Array();
var counter = 0;

if (rgxFfaUrl.test(document.body.innerHTML) | rgxDfaUrl.test(document.body.innerHTML)) {
	
	console.log("adtagexplorer.js: ad tag found");
	
	while(matchString = rgxFfaUrl.exec(document.body.innerHTML)){
		console.log("match " + counter + " found");
		FfaTagList[counter] = matchString;
		counter++;
	};
	
	// populate Dfa array for testing purposes
	DfaTagList.push("DFA Eintrag 1");
	DfaTagList.push("DFA Eintrag 2");
	DfaTagList.push("DFA Eintrag 2");
		
	console.log(FfaTagList.length);
	console.log(DfaTagList.length);
	
	responseString = "Message from content script.";
	
	chrome.extension.sendRequest({
		message: responseString,
		FfaTagList: FfaTagList,
		DfaTagList: DfaTagList
		}, 
		function(response) {});
	
} else {
	console.log("No ad tag was found!");
}